/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.com.jsepc.rep.process;

import cn.com.jsepc.rep.comm.ConstUtil;
import cn.com.jsepc.rep.vo.DomainVO;
import cn.com.jsepc.rep.vo.LinkVO;
import cn.com.jsepc.rep.vo.ProcessVO;
import cn.com.jsepc.rep.vo.SelectGridVO;
import com.jarp.db.DAO;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;
import javax.servlet.ServletException;
import net.sf.json.JSONArray;

/**
 *
 * @author 赵远
 */
public class GetCombox {
    
    public String getProcess(){
        String res="";
        String sql="select * from tb_process";
        DAO dao=new DAO();
        try {
            List<ProcessVO> lstResults = new ArrayList<ProcessVO>();
            Vector v=dao.getDataSet(ConstUtil.DBNAME, sql);
            if (v != null) {
                for (int i = 0; i < v.size(); i++) {
                    Hashtable hashRows = (Hashtable) v.get(i);
                    ProcessVO pro = new ProcessVO();
                    pro.setId((String)hashRows.get("PROCESSID"));
                    pro.setProcessCode((String)hashRows.get("PROCESSCODE"));
                    pro.setProcessDesc((String)hashRows.get("PROCESSDESC"));
                    pro.setText((String)hashRows.get("PROCESSNAME"));
                    lstResults.add(pro);
                }
                JSONArray json = new JSONArray();
                json = JSONArray.fromObject(lstResults);                
                res = json.toString();
            }
        } catch (ServletException ex) {
        }
        return res;
    }
    
    public String getDomain(){
        String res="";
        String sql="select * from tb_domain";
        DAO dao=new DAO();
        try {
            List<DomainVO> lstResults = new ArrayList<DomainVO>();
            Vector v=dao.getDataSet(ConstUtil.DBNAME, sql);
            if (v != null) {
                for (int i = 0; i < v.size(); i++) {
                    Hashtable hashRows = (Hashtable) v.get(i);
                    DomainVO pro = new DomainVO();
                    pro.setText((String)hashRows.get("DOMAINNAME"));
                    pro.setDomainDesc((String)hashRows.get("DOMAINDESC"));
                    pro.setId((String)hashRows.get("DOMAINID"));
                    lstResults.add(pro);
                }
                JSONArray json = new JSONArray();
                json = JSONArray.fromObject(lstResults);                
                res = json.toString();
            }
        } catch (ServletException ex) {
        }
        return res;
    }
    
    public String getLifecycle(){
        String res="";
        String sql="select * from tb_process_lifecycle";
        DAO dao=new DAO();
        try {
            List<DomainVO> lstResults = new ArrayList<DomainVO>();
            Vector v=dao.getDataSet(ConstUtil.DBNAME, sql);
            if (v != null) {
                for (int i = 0; i < v.size(); i++) {
                    Hashtable hashRows = (Hashtable) v.get(i);
                    DomainVO pro = new DomainVO();
                    pro.setText((String)hashRows.get("LIFECYCLENAME"));
                    pro.setDomainDesc((String)hashRows.get("LIFECYCLEDESC"));
                    pro.setId((String)hashRows.get("LIFECYCLEID"));
                    lstResults.add(pro);
                }
                JSONArray json = new JSONArray();
                json = JSONArray.fromObject(lstResults);                
                res = json.toString();
            }
        } catch (ServletException ex) {
        }
        return res;
    }
    
     public String getLink(){
        String res="";
        String sql="select * from tb_link";
        DAO dao=new DAO();
        try {
            List<LinkVO> lstResults = new ArrayList<LinkVO>();
            Vector v=dao.getDataSet(ConstUtil.DBNAME, sql);
            if (v != null) {
                for (int i = 0; i < v.size(); i++) {
                    Hashtable hashRows = (Hashtable) v.get(i);
                    LinkVO pro = new LinkVO();
                    pro.setId((String)hashRows.get("LINKID"));
                    pro.setLinkcode((String)hashRows.get("LINKCODE"));
                    pro.setLinkDesc((String)hashRows.get("LINKDESC"));
                    pro.setText((String)hashRows.get("LINKNAME"));
                    lstResults.add(pro);
                }
                JSONArray json = new JSONArray();
                json = JSONArray.fromObject(lstResults);                
                res = json.toString();
            }
        } catch (ServletException ex) {
        }
        
        return res;
    }
}
